package com.gexiaobao.pigeon.ui.auction

import android.content.res.ColorStateList
import android.os.Bundle
import androidx.core.content.ContextCompat
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.BaseActivity
import com.gexiaobao.pigeon.app.util.StatusBarUtil
import com.gexiaobao.pigeon.databinding.ActivityAuctionAllOrderBinding
import com.gexiaobao.pigeon.ui.auction.fragment.FragmentAuctionOrder
import com.gexiaobao.pigeon.viewmodel.AuctionViewModel
import com.google.android.material.tabs.TabLayout
import me.hgj.jetpackmvvm.ext.util.setOnclickNoRepeat

/**
 * @Author      : hxw
 * @Date        : 2024/11/26 17:37
 * @Describe    : 拍卖全部订单
 */
class ActivityAuctionAllOrder : BaseActivity<AuctionViewModel, ActivityAuctionAllOrderBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        StatusBarUtil.setTranslucentForImageView(this, 0, null)
        mDatabind.includeBar.tvTitle.text = "我的订单"
        initViewPager()
    }

    override fun onBindViewClick() {
        super.onBindViewClick()
        setOnclickNoRepeat(mDatabind.includeBar.ivBack) {
            when (it) {
                mDatabind.includeBar.ivBack -> finish()
            }
        }
    }

    private fun initViewPager() {
        mDatabind.tabLayout.tabRippleColor = ColorStateList.valueOf(ContextCompat.getColor(this, android.R.color.transparent))
        val tab1 = mDatabind.tabLayout.newTab().setText(getString(R.string.market_shop_order_list_for_fragment_layout_activity_my_order_tab_all))
        mDatabind.tabLayout.addTab(tab1)
        val tab2 = mDatabind.tabLayout.newTab().setText(getString(R.string.market_shop_order_list_for_fragment_layout_activity_my_order_tab_unpay))
        mDatabind.tabLayout.addTab(tab2)
        val tab3 =
            mDatabind.tabLayout.newTab().setText(getString(R.string.market_shop_order_list_for_fragment_layout_activity_my_order_tab_unrecieve))
        mDatabind.tabLayout.addTab(tab3)
        val tab4 = mDatabind.tabLayout.newTab().setText(getString(R.string.market_shop_order_list_for_fragment_layout_activity_my_order_tab_complete))
        mDatabind.tabLayout.addTab(tab4)

        mDatabind.tabLayout.addOnTabSelectedListener(object : TabLayout.BaseOnTabSelectedListener<TabLayout.Tab> {
            override fun onTabReselected(p0: TabLayout.Tab) {}
            override fun onTabUnselected(p0: TabLayout.Tab) {}

            override fun onTabSelected(p0: TabLayout.Tab) {
                replaceFragments(p0.position)
            }
        })
        replaceFragments(0)
    }

    private fun replaceFragments(position: Int) {
        supportFragmentManager.beginTransaction().apply {
            when (position) {
                0 -> replace(R.id.frameLayoutAuctionAllOrder, FragmentAuctionOrder.newInstance(""))//全部订单
                1 -> replace(R.id.frameLayoutAuctionAllOrder, FragmentAuctionOrder.newInstance("2"))//等待支付
                2 -> replace(R.id.frameLayoutAuctionAllOrder, FragmentAuctionOrder.newInstance("3,4"))//等待收货
                3 -> replace(R.id.frameLayoutAuctionAllOrder, FragmentAuctionOrder.newInstance("5"))//已经收货
            }
        }.commitAllowingStateLoss()
    }
}